package main

import (
	"flag"
	"fmt"
	"server/internal/app/api/admin"
	"server/internal/core"
	"server/internal/core/config"
	"server/internal/core/server"
)

var configFile string
var command string

func main() {
	// 解析命令行参数
	flag.StringVar(&configFile, "config", "./config.toml", "config file")
	flag.StringVar(&command, "command", "server", "command")
	flag.Parse()

	// 执行命令
	switch command {
	case "server":
		startServer()
	case "generate-config":
		generateConfig()
	}
}

// start 启动服务
func startServer() {
	if err := core.Init(configFile); err != nil {
		fmt.Println("Failed to init core:", err)
		return
	}
	// 注册路由
	router := server.GetRouter()
	admin.Register(router) // 注册admin路由

	// 启动server
	if err := server.Run(); err != nil {
		fmt.Println("Failed to start server:", err)
		return
	}
	fmt.Println("Server started successfully")
}

// generateConfig 生成配置文件
func generateConfig() {
	config := config.GenerateConfig()
	fmt.Println(config)
}
